home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.Stanford.EDU!microunity!toms
- From: toms@MicroUnity.com (Tom Sanders)
- Subject: Re: Float calculations
- Message-ID: <DM458u.F1y@microunity.com>
- Sender: usenet@microunity.com (news id)
- Organization: MicroUnity Systems Engineering, Inc.
- References: <4eqssf$d9q@camelot.ccs.neu.edu>
- Date: Thu, 1 Feb 1996 20:07:42 GMT
-
- In article <4eqssf$d9q@camelot.ccs.neu.edu>, jason@ccs.neu.edu (Jason Leatherman) writes:
- |>
- |> Hi,
- |>
- |> Check out the results I get when running this simple program on a
- |> Sparc/UNIX system, compiled with gcc:
- |>
- |> #include <stdio.h>
- |>
- |> void main()
- |> {
- |> float a, b;
- |>
- |> printf("%0.10f %0.10f %0.10f\n", 99974.0, 50.0, 99974.0/50.0);
- |>
- |> a = 99974.0;
- |> b = 50.0;
- |> printf("%0.10f %0.10f %0.10f\n", a, b, a/b);
- |> }
- |>
- |> The output is:
- |> 99974.0000000000 50.0000000000 1999.4800000000
- |> 99974.0000000000 50.0000000000 1999.4799804688
- |>
- |> Why do the divisions produce different results? This is probably some
- |> simple thing that I've forgotten, but I haven't figured it out yet. Does
- |> anyone know? Note that compiling with the -ffloat-store flag didn't make
- |> a difference.
- |> Thanks for any help,
- |>
- |> Jason
-
- For what it's worth, cc on both HP and Sun workstations do not behave
- this way, but gcc on both machines do.
-
- Tom Sanders
-